package com.cheer.dao;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author cheer
 */
@Repository
@Slf4j
public class PrizeCacheDao {

    // H5 抽奖独有
    private static final String PRIZE_KEY = "h5:match:prize";

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public Boolean addPrize(Long awardId) {
        try {
            stringRedisTemplate.opsForList().leftPush(PRIZE_KEY, String.valueOf(awardId));
            return true;
        } catch (Exception e) {
            log.error("add prize fail", e);
            return false;
        }
    }

    public String getPrize() {
        return stringRedisTemplate.opsForList().rightPop(PRIZE_KEY);
    }
}
